

project , uses(../data_output/legislators_klarner.dta)



	***********
	** New York
	** No term limits
	***********	
	use ../data_output/legislators_klarner.dta, clear
	keep if state=="NY" & chamber=="house"
	keep if regexm(term, "1999|2001|2003|2005|2007|2009|2011|2013|2015")
	gen lastname = trim(regexs(1)) if regexm(lower(CandName),"([^,]+)")
	gen firstname = trim(regexs(1)) if regexm(lower(CandName),",( [^ ]+)")
	gen mergename = lastname +", " +firstname 
	bys chamber mergename term: gen n = _n
	by chamber mergename term: egen mean_n=mean(n)
	replace mergename = CandName if mean_n>1  //firstname  + " " +  lastname //firstname+ ". "
	drop n mean_n
	save ../data_output/legislators_NY_house_1999_2016.dta, replace
project, creates(../data_output/legislators_NY_house_1999_2016.dta)		
	
	
project, original(../data_input/NY/ny_bills.csv)
	
	import delimited using ../data_input/NY/ny_bills.csv,  clear  delimiters(";") bindquotes(strict) encoding("utf-8") varnames(1)
	gen mergename = lower(sponsor)
	rename session term
	replace chamber="house"
	replace mergename = subinstr(mergename, "'","",.)
	replace mergename = subinstr(mergename, "-","",.)
	replace mergename = "molinaro, marc" if mergename=="molinaro, marcus" & regexm(term, "2007|2009|2011")

	replace mergename = "zebrowski, kenneth" if mergename=="zebrowski, ken" & regexm(term, "2007|2009|2011|2013|2015")
	replace mergename = "hoyt, william" if mergename=="hoyt, william b" & regexm(term, "1999|2001|2003|2005|2007|2009|2011")	
	replace mergename = "hyerspencer, donna" if mergename=="hyerspencer, janele" & regexm(term, "2007|2009")
	replace mergename = "roberts, sam" if mergename=="roberts, samuel" & regexm(term, "2011|2013|2015")
	replace mergename = "perry, n." if mergename=="perry, nick" & regexm(term, "1999|2001|2003|2005|2007|2009|2011|2013|2015")
	replace mergename = "miller, donald" if mergename=="miller, don" & regexm(term, "2011")
	replace mergename = "reilly, robert" if mergename=="reilly, bob" & regexm(term, "2005|2007|2009|2011")
	replace mergename = "nortz, h." if mergename=="nortz, h" & regexm(term, "1999|2001")
	replace mergename = "stirpe, albert" if mergename=="stirpe, al" & regexm(term, "2013|2015")	
	replace mergename = "simon, jo" if mergename=="simon, jo anne" & regexm(term, "2015")
	replace mergename = "cole, michael" if mergename=="cole, mike" & regexm(term, "2007")
	replace mergename = "denis, nelson" if mergename=="denis, nelsen" & regexm(term, "1999")
	replace mergename = "levy, steven" if mergename=="levy, steve" & regexm(term, "2001|2003")
	replace mergename = "russell, addie" if mergename=="jenne, addie" & regexm(term, "2009|2011|2013|2015")
	replace mergename = "walker, rob" if mergename=="walker, richard" & regexm(term, "2007|2009")

	merge m:1 mergename term using ../data_output/legislators_NY_house_1999_2016.dta
	*7 observations do not merge
	drop if _merge==1
	drop _merge
	save ../data_output/bills_by_sponsor_NY_1999_2016.dta, replace
	
project, creates(../data_output/bills_by_sponsor_NY_1999_2016.dta)		
	
	
	
	use ../data_output/bills_by_sponsor_NY_1999_2016.dta, clear
	drop sponsor
	gen termlimited=0
	gen sponsor = 1 if bill!=""
	collapse (sum) sponsor (first) elections_* terms_in_office win TermLengthActual CandName district chamber state party mergename inoffice year termlimited vtsh, by(CandId term )
	save ../data_output/total_bills_by_sponsor_NY_1999_2016.dta, replace	
	
	
project, creates(../data_output/total_bills_by_sponsor_NY_1999_2016.dta)		
	
	